package cn.tedu.ivos2.user.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.user.mapper.UserMapper;
import cn.tedu.ivos2.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos2.user.pojo.dto.UserQuery;
import cn.tedu.ivos2.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos2.user.pojo.vo.UserVO;
import cn.tedu.ivos2.user.service.impl.UserServiceImpl;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 边拾柱
 * @date 2024/12/13 16:44
 */
@Slf4j
@RestController
@RequestMapping("/v1/user")
@Api(tags = "2. 用户模块")
public class UserController {

    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private UserMapper userMapper;

    @PostMapping("login")
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 10)
    public JsonResult login(UserLoginParam userLoginParam) {
        log.debug("开始处理【用户登录】的请求，参数：{}", userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }


    @PostMapping("save")
    @ApiOperation("保存/更新用户信息")
    @ApiOperationSupport(order = 20)
    public JsonResult saveUserInfo(UserSaveParam userSaveParam) {
        log.debug("开始处理【保存/更新用户信息】的请求，参数：{}", userSaveParam);
        userService.saveUserInfo(userSaveParam);
        return JsonResult.ok();
    }


    @GetMapping("select")
    @ApiOperation("查询全部或条件用户")
    @ApiOperationSupport(order = 30)
    public JsonResult selectUser(UserQuery userQuery) {
        log.debug("开始处理【查询全部或条件用户】的请求，参数：{}", userQuery);
        List<UserVO> userVOS = userService.selectUser(userQuery);
        return JsonResult.ok(userVOS);
    }

    @PostMapping("update/password/{id}")
    @ApiOperation("重置用户密码")
    @ApiOperationSupport(order = 40)
    public JsonResult selectUser(@PathVariable Long id) {
        log.debug("开始处理【重置用户密码】的请求，参数：{}", id);
        userService.resetPassword(id);
        return JsonResult.ok();
    }

    @PostMapping("delete/{userId}")
    @ApiOperation("删除用户")
    @ApiOperationSupport(order = 50)
    public JsonResult deleteByUserId(@PathVariable Long userId) {
        log.debug("开始处理【删除用户】的请求，参数：{}", userId);
        userService.deleteByUserId(userId);
        return JsonResult.ok();
    }


    @PostMapping("update/status/{userId}/{status}")
    @ApiOperation("更改用户状态")
    @ApiOperationSupport(order = 60)
    public JsonResult updateUserStatus(@PathVariable Long userId, @PathVariable String status) {
        log.debug("修改用户状态，userId={},status={}",userId,status);
        userService.updateUserStatus(userId,status);
        return JsonResult.ok();
    }



}
